
//判断芯片类型 设置pin
void switchChip(uint32_t chipId) {
  if (chipId == 2716 || chipId == 2732) {
    chip27_24P();
  } else if (chipId == 2764 || chipId == 27128 || chipId == 27256 || chipId == 27512) {
    chip27_28P();
  } else if (chipId == 27010 || chipId == 27020 || chipId == 27040 || chipId == 27080) {
    chip27_32P();
  } else if (chipId == 2816) {
    chip28_24P();
  } else if (chipId == 2817 || chipId == 2863 || chipId == 2864 || chipId == 28256) {
    chip28_28P();
  } else if (check29InChips(chipId)) {
    chip29();
  } else {
    chip29();
  }
}

void chip27_24P() {
  //24脚VCC
  pinMode(VCC_24PIN, OUTPUT);
  digitalWrite(VCC_24PIN, HIGH);

  portMode(0, OUTPUT);
  portWrite(0, 0);

  pinMode(Add_8, OUTPUT);
  pinMode(Add_9, OUTPUT);
  digitalWrite(Add_8, LOW);
  digitalWrite(Add_9, LOW);

}

void chip27_28P() {
  pinMode(chip28WE, OUTPUT);
  digitalWrite(chip28WE, HIGH);
  pinMode(chip_OE, OUTPUT);
  pinMode(chip_CE, OUTPUT);
  digitalWrite(chip_OE, HIGH);
  digitalWrite(chip_CE, HIGH);
  //28脚VCC
  pinMode(VCC_28PIN, OUTPUT);
  digitalWrite(VCC_28PIN, HIGH);

  portMode(0, OUTPUT);
  portWrite(0, 0);

  pinMode(Add_8, OUTPUT);
  pinMode(Add_9, OUTPUT);
  pinMode(Add_10, OUTPUT);
  pinMode(Add_11, OUTPUT);
  pinMode(Add_12, OUTPUT);
  pinMode(Add_13, OUTPUT);
  pinMode(A27_14, OUTPUT);
  pinMode(A27_15, OUTPUT);

  digitalWrite(A27_14, LOW);
  digitalWrite(A27_15, LOW);

}

void chip27_32P() {
  pinMode(chip_OE, OUTPUT);
  pinMode(chip_CE, OUTPUT);
//  pinMode(A27_32P_VPP, OUTPUT);
//  pinMode(A27_32P_PGM, OUTPUT);
  digitalWrite(chip_OE, HIGH);
  digitalWrite(chip_CE, HIGH);
//  digitalWrite(A27_32P_VPP, HIGH);
//  digitalWrite(A27_32P_PGM, HIGH);

  portMode(0, OUTPUT);
  portWrite(0, 0);
  pinMode(Add_8, OUTPUT);
  pinMode(Add_9, OUTPUT);
  pinMode(Add_10, OUTPUT);
  pinMode(Add_11, OUTPUT);
  pinMode(Add_12, OUTPUT);
  pinMode(Add_13, OUTPUT);
  pinMode(A27_32P_14, OUTPUT);
  pinMode(A27_32P_15, OUTPUT);
  pinMode(A27_32P_16, OUTPUT);
  pinMode(A27_32P_17, OUTPUT);
  pinMode(A27_32P_18, OUTPUT);
  pinMode(A27_32P_19, OUTPUT);

  digitalWrite(A27_32P_14, LOW);
  digitalWrite(A27_32P_15, LOW);
  digitalWrite(A27_32P_16, LOW);
  digitalWrite(A27_32P_17, LOW);
  digitalWrite(A27_32P_18, LOW);
  digitalWrite(A27_32P_19, LOW);

}
void chip28_24P(){
  pinMode(VCC_24PIN, OUTPUT);
  pinMode(C2816_WE, OUTPUT);
  pinMode(chip_OE, OUTPUT);
  pinMode(chip_CE, OUTPUT);
  digitalWrite(chip_OE, HIGH);
  digitalWrite(chip_CE, HIGH);
  digitalWrite(C2816_WE, HIGH);
  digitalWrite(VCC_24PIN, HIGH);
  
  portMode(0, OUTPUT);
  portWrite(0, 0);
  pinMode(Add_8, OUTPUT);
  pinMode(Add_9, OUTPUT);
  pinMode(Add_10, OUTPUT);
}

void chip28_28P() {
  pinMode(chip28WE, OUTPUT);
  digitalWrite(chip28WE, HIGH);
  pinMode(chip_OE, OUTPUT);
  pinMode(chip_CE, OUTPUT);
  digitalWrite(chip_OE, HIGH);
  digitalWrite(chip_CE, HIGH);
  //28脚VCC
  pinMode(VCC_28PIN, OUTPUT);
  digitalWrite(VCC_28PIN, HIGH);

  portMode(0, OUTPUT);
  portWrite(0, 0);
  pinMode(Add_8, OUTPUT);
  pinMode(Add_9, OUTPUT);
  pinMode(Add_10, OUTPUT);
  pinMode(Add_11, OUTPUT);
  pinMode(Add_12, OUTPUT);
  pinMode(Add_13, OUTPUT);
  pinMode(A28_14, OUTPUT);

  digitalWrite(A28_14, LOW);

}

void chip29() {
  //32脚we设置高
  pinMode(chip29WE, OUTPUT);
  digitalWrite(chip29WE, HIGH);
  pinMode(chip_CE, OUTPUT);
  digitalWrite(chip_CE, HIGH);
  pinMode(chip_OE, OUTPUT);
  digitalWrite(chip_OE, HIGH);

  //A0-A15
  portMode(0, OUTPUT);
  portMode(2, OUTPUT);
//  portWrite(0, 0x00);
//  portWrite(2, 0x00);

  pinMode(A29_16, OUTPUT);
  pinMode(A29_17, OUTPUT);
  pinMode(A29_18, OUTPUT);

//  digitalWrite(A29_16, LOW);
//  digitalWrite(A29_17, LOW);
//  digitalWrite(A29_18, LOW);
}
